package com.wn.inventory.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;

/**
 * @ author     ：NST
 * @ date       ：Created in 2022/10/24 15:02
 * @ description：自定义事务管理器
 * @ modified By：
 * @ version:
 */
@Component
public class SelfTransactionManager {
    private TransactionStatus transactionStatus;

    @Autowired
    private PlatformTransactionManager platformTransactionManager;

    @Autowired
    private TransactionDefinition transactionDefinition;

    /*
     *手动开启事务
     */
    public TransactionStatus begin() {
        TransactionStatus status = platformTransactionManager.getTransaction(transactionDefinition);
        return status;
    }
    /*
     *手动提交事务
     */
    public void commit(TransactionStatus transactionStatus){
        platformTransactionManager.commit(transactionStatus);
    }
    /*
     *手动回滚事务
     */
    public void roallback(TransactionStatus transactionStatus){
        platformTransactionManager.rollback(transactionStatus);
    }
}
